const vm = new Vue({
    el: '#main',
    data: {
        name: '',
        tel: '',
        need: '',
        residueLength: 100,
    },
    methods: {
        submit,
    },
});

function apiready() {
    fxj.fixLayout();

}

async function submit() {
    if (!checkIpt()) return;
    const close = fxj.dialog.loading({noBg: true});
    const res = await ajax({
        url: 'home/DepartureService/index',
        data: {
            name: vm.name,
            phone: vm.tel,
            content: vm.need,
        },
    });
    close();
    toast(res.msg);
    if (res.err === 0) {
        setTimeout(fxj.closeWin, 1000);
    }
}

function checkIpt() {
    if (!vm.name) {
        toast('请输入您的姓名');
    }
    else if (!vm.tel) {
        toast('请输入您的手机号码');
    }
    else if (!vm.need) {
        toast('请告诉我们您的需求');
    }
    return isExist(vm.name) && isExist(vm.tel) && isExist(vm.need);
}

function checkIptLength() {
    vm.residueLength = 100;
    vm.residueLength -= vm.need.length;
    if (vm.residueLength < 0) {
        vm.need = vm.need.slice(0, vm.residueLength);
        vm.residueLength = 0;
    }
}